home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 3.9 KB | 112 lines | [TEXT/CCL2] |
- ;;; perspective-projection.lisp
- ;;;
- ;;; Paul McCartney, Spring 1992
- ;;;
- ;;; Copyright © 1992 Paul McCartney. All Rights Reserved.
- ;;;
- ;;; Washington University Medical Informatics Training Program
- ;;;
- ;;; DESCRIPTION:
- ;;;
- ;;; This provides code for displaying 3D objects using simple perspective
- ;;; projection. Images are projected onto the z=0 plane from an
- ;;; observer's point of view at some distance from the plane.
- ;;;
- ;;; USE:
- ;;;
- ;;; perspective-projection - class for 3D images
- ;;; :distance - viewer distance from the z=0 plane
- ;;; :view-3D-origin - 2D view coordinate of the 3D origin (i.e. (0, 0, 0))
- ;;;
- ;;; perspective-make-point - make 2D real view point from 3D point
- ;;; view-point-to-3D - given a real view point, translate it into
- ;;; a 3D point (x, y) at the plane z=0
- ;;; draw-block-below-horizon - draw a brick-shaped object in 3D
- ;;;
- ;;; HISTORY:
- ;;;
- ;;; 6/20/92 Created. - PM
- ;;;
-
- (in-package :ccl)
-
- (require :quickdraw)
- (require :graphics-tools)
-
- (eval-when (:compile-toplevel :load-toplevel :execute)
- (export '(perspective perspective-make-point view-point-to-3D
- draw-block-below-horizon)
- :ccl))
-
-
- (defstruct perspective
- (distance 100 :type fixnum)
- (view-3D-origin #@(0 0) :type fixnum) )
-
-
- (defun perspective-make-point (p x y &optional z)
- (let* ((x1 (if z x (point-h x)))
- (y1 (if z y (point-v x)))
- (z1 (if z z y))
- (d1 (+ (perspective-distance p) z1))
- (x2 (+ (round (* (perspective-distance p) x1) d1)
- (point-h (perspective-view-3D-origin p))))
- (y2 (+ (round (* (perspective-distance p) y1) d1)
- (point-v (perspective-view-3D-origin p)))))
- (make-point x2 y2)))
-
-
- (defun view-point-to-3D (p point)
- (let* ((x (point-h point))
- (y (point-v point)))
- (make-point (- x (point-h (perspective-view-3D-origin p)))
- (- y (point-v (perspective-view-3D-origin p))))))
-
-
- (defmethod draw-block-below-horizon ((view simple-view) p topleft bottomright color depth)
- (let* ((p1 (view-point-to-3D p topleft))
- (p4 (view-point-to-3D p bottomright))
- (p2 (make-point (point-h p4) (point-v p1)))
- (p3 (make-point (point-h p1) (point-v p4)))
- (vp1 (perspective-make-point p p1 0))
- (vp2 (perspective-make-point p p2 0))
- (vp3 (perspective-make-point p p3 0))
- (vp4 (perspective-make-point p p4 0))
- (vp5 (perspective-make-point p p1 depth))
- (vp6 (perspective-make-point p p2 depth))
- (vp7 (perspective-make-point p p3 depth))
- (vp8 (perspective-make-point p p4 depth))
- (front-color color)
- (top-color (change-brightness color 1.1))
- (side-color (change-brightness color 1.4))
- (outline-color (change-brightness color 2))
- (front-poly (make-polygon-shape view vp1 vp2 vp4 vp3 vp1))
- (top-poly (make-polygon-shape view vp1 vp2 vp6 vp5 vp1))
- (side-left-poly (make-polygon-shape view vp2 vp6 vp8 vp4 vp2))
- (side-right-poly (make-polygon-shape view vp1 vp5 vp7 vp3 vp1)))
-
- (with-focused-view view
- (with-fore-color side-color
- (paint-polygon view side-left-poly))
- (with-fore-color outline-color
- (frame-polygon view side-left-poly))
- (with-fore-color side-color
- (paint-polygon view side-right-poly))
- (with-fore-color outline-color
- (frame-polygon view side-right-poly))
- (with-fore-color front-color
- (paint-polygon view front-poly))
- (with-fore-color outline-color
- (frame-polygon view front-poly))
- (with-fore-color top-color
- (paint-polygon view top-poly))
- (with-fore-color outline-color
- (frame-polygon view top-poly)))
-
- (kill-polygon front-poly)
- (kill-polygon top-poly)
- (kill-polygon side-left-poly)
- (kill-polygon side-right-poly) ))
-
-
- (provide :perspective-projection)